package com.ymatou.iapi.couponmanage.testcase;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.couponmanage.parameter.BatchInfo;
import com.ymatou.iapi.couponmanage.parameter.CreateBagBean;
import com.ymatou.iapi.couponmanage.service.CreateBagCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
/**
*创建套券
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_CreateBag{
	private static CreateBagBean createbagBean;
	private static CreateBagCall createbagCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("创建套券");
	}

	@Before
	public void caseUp() {
		createbagBean=new CreateBagBean();
		createbagCall=new CreateBagCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(createbagCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateBag_001() {
		Logger.start(true,"创建套券");
		try {
			CreateBagBean CreateBagBean = new CreateBagBean();
			CreateBagBean.setName("自动化创建套券领取优惠券");
			CreateBagBean.setDescription("自动化测试创建套券领取优惠券描述");
			CreateBagBean.setOperatorId(222222);
			CreateBagBean.setApplyUser("自动化user111");
			CreateBagBean.setApplyMemo("自动化测试创建套券领取优惠券申请理由");
			CreateBagBean.setEffectiveType(0);
			CreateBagBean.setEffectiveValidType(0);
			CreateBagBean.setEffectiveDays(0);
			
			Date dNow = new Date(); // 当前时间
			Date dBefore = new Date();
			Date dAfter = new Date();

			Calendar calendar1 = Calendar.getInstance(); // 得到日历
			calendar1.setTime(dNow);// 把当前时间赋给日历
			calendar1.add(Calendar.DAY_OF_MONTH, -1); // 设置为前一天
			dBefore = calendar1.getTime(); // 得到前一天的时间

			Calendar calendar2 = Calendar.getInstance(); // 得到日历
			calendar2.setTime(dNow);// 把当前时间赋给日历
			calendar2.add(Calendar.DAY_OF_MONTH, 10); // 设置为后十天
			dAfter = calendar2.getTime(); // 得到前一天的时间

			CreateBagBean.setValidStart(dBefore);
			CreateBagBean.setValidEnd(dAfter);
			CreateBagBean.setAcquireStartTime(dBefore);
			CreateBagBean.setAcquireEndTime(dAfter);
			// 获取优惠券方式(1:领取(默认) 2:兑换)
			CreateBagBean.setAcquireMethod(2);
			CreateBagBean.setTotalNum(10);
			CreateBagBean.setReceiveTimesPerUser(1);
			CreateBagBean.setReceiveUserType(0);
			List<Integer> usePlatforms = new ArrayList<Integer>();
			/*
			 * usePlatforms.add(1); usePlatforms.add(2); usePlatforms.add(3);
			 */
			CreateBagBean.setUsePlatformIds(usePlatforms);
			CreateBagBean.setApplyDepartment(1);
			CreateBagBean.setImpresetInvoiceId("111111");
			
			List<BatchInfo> BatchInfos=new ArrayList<BatchInfo>();
			BatchInfo info=new BatchInfo();
			info.setCouponName("自动化创建套券优惠券名称-子套券");
			info.setCouponDes("自动化创建套券优惠券描述-子套券");
			info.setApplyMemo("自动化创建申请理由-子套券");
			info.setOrderMinAmount(new BigDecimal(2));
			info.setDeductionMaxAmount(new BigDecimal(1));
			List<String> productIds = new ArrayList<String>();
			info.setProductIds(productIds);
			List<Integer> SellerIds = new ArrayList<Integer>();
			info.setSellerIds(SellerIds);
			List<Integer> ActivityIds = new ArrayList<Integer>();
			info.setActivityIds(ActivityIds);
			List<Integer> Brands = new ArrayList<Integer>();
			info.setBrands(Brands);
			List<Integer> Countrys = new ArrayList<Integer>();
			info.setCountrys(Countrys);
			List<Integer> Categories = new ArrayList<Integer>();
			info.setCategories(Categories);
			info.setLimitPspProduct(false);
			BatchInfos.add(info);
			CreateBagBean.setBatchInfos(BatchInfos);
			createbagCall.setData(CreateBagBean);
			createbagCall.callService();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}